package org.reborn.utils.actors

/**
 * This is a helper class for using actors when you want to handle 
 * expected thrown exceptions.
 */
class DeferThrownException[T](val func:()=>T) {
  private var ex:Throwable = null
  private var ret:Option[T] = None
  try{
    ret = Some(func())
  }
  catch{
    case e => ex = e;
  }
  
  def get():T = ret getOrElse (throw ex)
}

object ActorExceptionHandler{
  def DeferThrow[T](func:()=>T) = new DeferThrownException(func);
  
  def GetOrThrow[T](obj:Any):T = {
    obj.asInstanceOf[DeferThrownException[T]].get
  }
}
